package {

	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextField;
	import flash.display.Sprite;
	
	/**
	 * @author Jorge Hernandez
	 */
	public class TestView extends Sprite {
		
		
		// PROPERTIES
		
		public static var count:uint = 0;
		public var message:String;
		public var ob:Object;
		
		
		// PUBLIC METHOS
		
		public function init():void {
			
			trace("*** TestView.init (" + name + ") - " + (++count));
			
			var square:Sprite = new Sprite();
			square.graphics.beginFill(0xCCDDFF);
			square.graphics.drawRect(0, 0, 300, 300);
			square.graphics.endFill();
			square.x = stage.stageWidth / 2 - square.width / 2;
			square.y = stage.stageHeight / 2 - square.height / 2;
			addChild(square);
			
			var textField:TextField = new TextField();
			textField.x = 25;
			textField.y = 25;
			textField.width = 275;
			textField.height = 275;
			textField.multiline = true;
			textField.wordWrap = true;
			textField.selectable = false;
			
			textField.htmlText = "<b>" + name + "</b>\n" + message;  
			var format:TextFormat = new TextFormat();
			format.size = 14; 
			format.leading = 4;
			format.font = "Helvetica"; 
			textField.setTextFormat(format);
			square.addChild(textField);
			
			addEventListener(MouseEvent.CLICK, clickHandler, false, 0, true);
			buttonMode = true;
			mouseChildren = false;
			
		}
		
		public function destroy():void {
			trace("*** TestView.destroy(" + name + ")");
		}
		
		public function tell(message:String, n:int = 1):void {
			for (var i:int = 0; i < n; i++)
				trace("*** TestView.TELL(" + n + "): " + message);
		}
		
		
		// EVENT HANDLERS
		
		private function clickHandler(event:MouseEvent):void {
			dispatchEvent(new DataEvent("viewClick", true, false, "DATA FROM VIEW CLICK"));
		}
		
		
	}
	
}
